package csl.blog.server.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import csl.blog.common.entity.User;
import csl.blog.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: TODO
 * @author: 隔山海
 * @date: 2021年07月15日 13:37
 */
@RequestMapping("user")
@RestController
@Slf4j
public class UserController{

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public boolean add(@RequestBody User user){
        user.setUserId(String.valueOf(IdWorker.getId()));
        return userService.save(user);
    }

    @RequestMapping(value = "/queryById",method = RequestMethod.GET)
    public List<User> queryByCondition(@RequestBody User user){
        LambdaQueryWrapper<User> query = new LambdaQueryWrapper<>();
        query.eq(User::getUserId,user.getUserId());
        return userService.list(query);
    }
}
